declare @temp table (Name varchar(100),oldprice money,mount int,newprice money)
declare @price money,@Idproducto int,@price2 money,@monto int,@qry nvarchar(100),@Nom nvarchar(50)
declare qProduct cursor for
	select pp.ListPrice,pp.ProductID--,plph.ProductID--,plph.ListPrice
	from Production.Product as pp
	--join Production.ProductListPriceHistory as plph on pp.ProductID=plph.ProductID
open qProduct 
fetch next from qProduct into @price,@Idproducto,@Nom--,@price2
while @@FETCH_STATUS=0
begin
if(@price<100)
begin
	update Production.Product set ListPrice=@price+(15*@price)/100
	set @price2=@price+(15*@price)/100
	set @monto=(15*@price)/100
	insert into Production.ProductListPriceHistory values (@Idproducto,GETDATE(),@price2,Getdate())
	insert into @temp values(@Nom,@price,@monto,@price2)
end
else
begin
	update Production.Product set ListPrice=(10*@price)/100
	set @price2=@price+(10*@price)/100
	set @monto=(10*@price)/100
	insert into Production.ProductListPriceHistory values (@Idproducto,GETDATE(),@price2,Getdate())
	insert into @temp values(@Nom,@price,@monto,@price2)
end
fetch next from qProduct into @price,@Idproducto,@Nom
	end
close qProduct
select*
from @temp



-----------------ejer 2

create table #temp1 table (NFibo int)
declare @valora    int=0
		,@valorb   int=1
		,@fun      int=0
		,@valori   int=0
		,@tope     int=3000
insert into @temp1 values(@valori)
set @valori=1
insert into @temp1 values(@valori)
while @fun<@tope
begin
set @fun=@valora+@valorb
if (@fun<@tope)
begin
insert into @temp1
		values (@fun)
set @valora=@valorb
set @valorb=@fun
end
end
merge into NORTHWND.dbo.Employees as tgt
using (select*
from Person.Person as pp
join @temp1 on pp.BusinessEntityId=@temp1.NFibo )as src (BusinessEntityId,FirstName,LastName,Title)
 when MATCHED Then UPDATE set 
							tgt.EmployeeId=src.BusinessEntityId
							,tgt.FirstName=src.FirstName
							,tgt.LastName=scr.LastName
							,tgt.Title=scr.Title
when Not matched then insert (BusinessEntityId,FirstName,LastName,Title)
 values(src.BusinessEntityId,src.FirstName,src.LastName,src.Title)
